
const tokens = {
	10001: {
		token: 'province'
	},
	20001: {
		token: 'city'
	},
	30001: {
		token: 'enterprise'
	}
}

const users = {
	'province':{
		userId: 10001,
		roleId: 1,
		token: 'province',
		authority: 16376
	},
	'city':{
		userId: 20001,
		roleId: 2,
		token: 'city',
		authority: 5136
	},
	'enterprise':{
		userId: 30001,
		roleId: 3,
		token: 'enterprise',
		authority: 6
	}
}

module.exports = [
	// user login
	{
		url: '/user/login',
		type: 'post',
		response: config => {
			const { userId, userPassword } = config.body
			const token = tokens[userId]

			// mock error
			if (!token) {
				return {
					code: 60204,
					message: '用户名或密码错误'
				}
			}

			return {
				code: 200,
				data: token
			}
		}
	},

	// get user info
	{
		url: '/user/info\.*',
		type: 'get',
		response: config => {
			const { token } = config.query
			const info = users[token]

			// mock error
			if (!info) {
				return {
					code: 50008,
					message: 'Token不存在'
				}
			}

			return {
				code: 200,
				data: info
			}
		}
	},

	// user logout
	{
		url: '/user/logout',
		type: 'post',
		response: _ => {
			return {
				code: 200,
				data: 'success'
			}
		}
	},

	{
		url: '/user/testConnection',
		type: 'get',
		response: _ => {
			return {
				code: 200,
				data: 'success'
			}
		}
	}
]
